package com.cloudcc.mobile.view.base;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cloudcc.mobile.R;
import com.cloudcc.mobile.dialog.CallLogLoadingDialog;
import com.cloudcc.mobile.manager.RunTimeManager;
import com.cloudcc.mobile.weight.LoadingDialog;

public abstract class BaseFragment extends CFragment {

private String mEns = RunTimeManager.getInstance().getlanguage();
	protected LoadingDialog mWaiting;
	CallLogLoadingDialog callLogLoadingDialogx ;
	@Override
	public void init() {
	}

	/**
	 * 显示 等待 的 dialog
	 * 
	 * @param message
	 *            提示语
	 * @return 返回 LoadingDialog
	 */
	protected LoadingDialog showWainting(String message) {
		mWaiting = new LoadingDialog(mContext, message);
		mWaiting.setCancelable(true);
		mWaiting.show();
		return mWaiting;
	}

	// 显示dialog但是不可点击
	protected LoadingDialog showWaintingno(String message) {
		mWaiting = new LoadingDialog(mContext, message);
		mWaiting.setCancelable(false);
		mWaiting.show();
		return mWaiting;
	}
	protected void showDialogTy(String text){
		callLogLoadingDialogx = new CallLogLoadingDialog(mContext,R.style.DialogLoadingTheme);
		callLogLoadingDialogx.show();
		callLogLoadingDialogx.settext(text);
	}
	/**
	 * 显示一个正在加载的默认
	 * 
	 * @return
	 */
	protected void showWainting() {
		if ("en".equals(mEns)) {
			 showDialogTy("loading...");
		}else{
			 showDialogTy("正在加载...");
	}
		
	}

	/**
	 * 显示一个正在加载的默认
	 * 
	 * @return
	 */
	protected void  showWaintingno() {
		if ("en".equals(mEns)) {
//			 showWaintingno("loading...");
			showDialogTy("loading...");
		}else{
//			 showWaintingno("正在加载...");
			showDialogTy("正在加载...");
	}
		
	}

	/**
	 * 显示 等待 的 dialog
	 * 
	 * @return 返回 LoadingDialog
	 */
	protected LoadingDialog createWainting() {
		mWaiting = new LoadingDialog(mContext);
		return mWaiting;
	}

	/**
	 * 取消 显示等待的dialog
	 */
	protected void dismissWainting() {
		if (callLogLoadingDialogx != null) {
			callLogLoadingDialogx.dismiss();
			callLogLoadingDialogx = null;
		}
	}
	protected void dismissDialogTy(){
		if (callLogLoadingDialogx != null) {
			callLogLoadingDialogx.dismiss();
			callLogLoadingDialogx = null;
		}
	}
	  public static Dialog createLoadingDialog(Context context, String msg) {

	        LayoutInflater inflater = LayoutInflater.from(context);
	        View v = inflater.inflate(R.layout.dialog_loading, null);// 得到加载view
	        LinearLayout layout = (LinearLayout) v.findViewById(R.id.dialog_view);// 加载布局
	        // main.xml中的ImageView
	        ImageView spaceshipImage = (ImageView) v.findViewById(R.id.img);
	        TextView tipTextView = (TextView) v.findViewById(R.id.text_view_message);// 提示文字
	        // 加载动画
	        Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(
	                context, R.anim.loading_animation);
	        // 使用ImageView显示动画
	        spaceshipImage.startAnimation(hyperspaceJumpAnimation);
	        tipTextView.setText(msg);// 设置加载信息

	        Dialog loadingDialog = new Dialog(context, R.style.DialogLoadingTheme);// 创建自定义样式dialog

	        loadingDialog.setCancelable(true);
	        loadingDialog.setContentView(layout, new LinearLayout.LayoutParams(
	                LinearLayout.LayoutParams.MATCH_PARENT,
	                LinearLayout.LayoutParams.MATCH_PARENT));// 设置布局
	        return loadingDialog;
	    }
}
